/*
 * OrthographicCamera.cpp
 *
 *  Created on: 19/05/2010
 *      Author: Nadav
 */

#include "OrthographicCamera.h"
#include "vectors.h"

OrthographicCamera::OrthographicCamera(Vec3f center, Vec3f projectionDir, Vec3f up, float size) {
	this->center = center;
	this->projectionDir = projectionDir;
	this->projectionDir.Normalize();
	this->imageSize = size;
	this->up = up;
	this->up.Normalize();
	// calculate the horizontal vector
	Vec3f().Cross3(horizontal, this->projectionDir, this->up);
	// make sure up is perpendicular to the rest
	Vec3f().Cross3(this->up, horizontal,this->projectionDir);
//	this->up.Negate();
}

OrthographicCamera::~OrthographicCamera() {
}

Ray OrthographicCamera::generateRay(Vec2f point) {
	Vec3f rayOrigin = center + up*(point.y()*imageSize-imageSize/2) + horizontal*(point.x()*imageSize-imageSize/2);
	Ray* ray = new Ray(projectionDir, rayOrigin);
	return *ray;
}
